Skip to content

README: fix jsonpath for pod name#19

Open
dhij wants to merge 1 commit intomasterfrom
dhij/podname-jsonpath
Open

README: fix jsonpath for pod name#19
dhij wants to merge 1 commit intomasterfrom
dhij/podname-jsonpath

Conversation

@dhij
Copy link
Copy Markdown

@dhij dhij commented May 12, 2023

-ojsonpath='{.items[0].metadata.name}' gave me a pod name for cilium so I was thinking we could use this approach or sort by .metadata.creationTimestamp before choosing items[0]

@dhij dhij requested a review from timoreimann May 12, 2023 12:13
```bash
NODE_NAME="my-node-name"
POD_NAME=$(kubectl -n kube-system get pods --field-selector spec.nodeName=${NODE_NAME} -ojsonpath='{.items[0].metadata.name}')
POD_NAME=$(kubectl -n kube-system get pods --field-selector spec.nodeName=${NODE_NAME} -ojsonpath='{.items[?(@.metadata.labels.name=="doks-debug")].metadata.name}')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach is to use the label that should uniquely identify doks-debug.

Personally, I generally prefer using custom columns over dealing with JSON whenever I can, so this is how I'd go about it:

POD_NAME=$(kubectl get pod -l name=doks-debug --field-selector spec.nodeName=${NODE_NAME} --no-headers -o custom-columns=:.metadata.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhij could you check in on that? Take care to add -n kube-system still if you use Timo's command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants